<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script type="text/javascript" src="/js/jquery.min.js"></script>
    <!--bootstrap-->
    <script src="/js/bootstrap/js/bootstrap.min.js"></script>
    <link rel="stylesheet" type="text/css" href="/js/bootstrap/css/bootstrap.min.css"/>
    <!--bootstrap-toastr-->
    <script type="text/javascript" src="/js/toastr/toastr.min.js"></script>
    <link rel="stylesheet" type="text/css" href="/js/toastr/toastr.css"/>
</head>
<body>
<form class="form-horizontal">
    <div class="form-group">
        <input type="hidden" name="id" id="id" th:value="${menu.id}">
        <input type="hidden" name="pid" id="pid" th:value="${menu.pid}">
    </div>
    <div class="form-group">
        <label for="name" class="col-sm-2 control-label">节点名称</label>
        <div class="col-sm-6">
            <input type="text" th:value="${menu.name}" class="form-control" id="name" placeholder="请输入">
        </div>
    </div>
    <div class="form-group">
        <label for="url" class="col-sm-2 control-label">url</label>
        <div class="col-sm-6">
            <input type="text" class="form-control" th:value="${menu.url}" id="url" placeholder="url">
        </div>
    </div>
    <div class="form-group">
        <div class="col-sm-offset-2 col-sm-10">
            <button type="button" class="btn btn-success" onclick="updateById()">确定</button>
        </div>
    </div>
</form>

</body>
<script>

    function updateById() {
        var menu = {
            "name": $('#name').val(),
            "url": $('#url').val(),
            "pid": $('#pid').val()
        }
        var parameter = JSON.stringify(menu);
        $.ajax({
            url: "/menu/" + $("#id").val(),
            dataType: "json",
            contentType: 'application/json;charset=UTF-8',
            type: "put",
            async: false, // ?
            data: parameter,
            success: function (data) {
                if (data.code == 200) {
                    toastr.success("修改成功");
                    setTimeout(function () {
                        parent.location.reload();
                    }, 1000);
                    // var index = parent.layer.getFrameIndex(window.name);
                    // parent.layer.close(index);
                }
            },
            error: function (e) {
                alert("系统错误");
            }
        })
    }

</script>
</html>